﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineMovieTicket.Services.IServices;
using OnlineMovieTicket.Services.Services;
using OnlineMovieTicket.Model;


namespace OnlineMovieTicket.WebForms.CheckBooking
{
    public partial class ViewBooking : System.Web.UI.Page
    {

        List<TransactionDetail> oTransactionDetail;

        protected void Page_Load(object sender, EventArgs e)
        {
            lblInfo.Text = string.Empty;
            customerdata.Visible = false;

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            oTransactionDetail = new List<TransactionDetail>();
            ITransactionService transService = new TransactionService();
            oTransactionDetail = transService.getCheckBookingByNric(txtNRIC.Text.ToUpper());

            if (oTransactionDetail.Count > 0)
            {
                grvCheckBooking.DataSource = oTransactionDetail;

                customerdata.Visible = true;
                lblCustomerName.Text = oTransactionDetail[0].CustomerName;
                lblEmail.Text = oTransactionDetail[0].Email;

            }
            else
            {
                lblInfo.Text = "Data not found, please try again.";
                grvCheckBooking.DataSource = null;
                customerdata.Visible = false;
                lblCustomerName.Text = string.Empty;
                lblEmail.Text = string.Empty;
            }

            grvCheckBooking.DataBind();
        }

        protected void grvCheckBooking_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType.Equals(DataControlRowType.DataRow))
            {
                Label seat = (Label)e.Row.FindControl("lblSeat");
                seat.Text = GetSeatNumbers(e.Row.RowIndex);
            }
        }

        string GetSeatNumbers(int iRow)
        {
            string strResult = string.Empty;

            foreach (string seat in oTransactionDetail[iRow].SeatNum)
            { 
                strResult += seat + ",";
                
            }

            return strResult.Remove(strResult.Length - 1, 1);
        
        }




    }
}